{{

  RFID Tag Side (remote client)

}}

CON

  _clkmode = xtal1 + pll16x
  _xinfreq = 5_000_000

  XBEE_DOUT_PIN = 10
  XBEE_DIN_PIN  = 11
  XBEE_MODE     = %0000
  XBEE_BAUD     = 9_600

  LED_PIN       = 19
  
obj

  xb    :       "FullDuplexSerial"  'comms to XBee.

var

  long  recv
  
pub go

  xb.start(XBEE_DOUT_PIN, XBEE_DIN_PIN, XBEE_MODE, XBEE_BAUD) 'start comms to XBee

  dira[LED_PIN] := 1            'sets to output

  'main loop
  repeat
    xb.tx("?")                  'prompt the host for validation

    recv := xb.rxtime(250)      'receive our response byte, wait 1/4 second max for response
    
    if recv == "!"              'if we receive a valid response, then execute the following...
      outa[LED_PIN] := 1        '  turn LED on
      waitcnt(cnt + 2*clkfreq)  '  wait 2 seconds
      outa[LED_PIN] := 0        '  turn LED off
      'waitcnt(cnt + clkfreq)   '  wait
      
    else                        'else, if something else was received
      outa[LED_PIN] := 0        '  didnt get an ! (got something else), turn the LED off

    waitcnt(cnt + (3*clkfreq))  'wait 3 seconds



  